package com.example.currentlimiting.demo.utils;

import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @author liulanhua
 * @date 2018/3/9
 */
@Data
public class WebResult implements Serializable {

    private boolean success;

    /**
     * 返回码
     */
    private Integer code;

    /**
     * 返回消息
     */
    private String msg;

    /**
     * 返回数据
     */
    private Object data;
    private Map<?, ?> map;
    private List<Map<String, Object>> list;


    public WebResult() {
    }

    public WebResult(Integer code, String msg) {
        super();
        this.msg = msg;
        this.code = code;
    }

    public WebResult(Integer code, Object data) {
        super();
        this.code = code;
        this.data = data;
    }
    public WebResult(Integer code, Object data, String msg) {
        super();
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public WebResult(Integer code, Map<?, ?> map) {
        super();
        this.code = code;
        this.map = map;
    }
    public WebResult(Integer code, Map<?, ?> map, String msg) {
        super();
        this.msg = msg;
        this.code = code;
        this.map = map;
    }

    public WebResult(Integer code, List<Map<String, Object>> list) {
        super();
        this.code = code;
        this.list = list;
    }
    public WebResult(Integer code, List<Map<String, Object>> list, String msg) {
        super();
        this.msg = msg;
        this.code = code;
        this.list = list;
    }

    /**
     * 初始失败方法
     *
     * @see [类、类#方法、类#成员]
     */
    public void invokeFail() {
        this.data = null;
        this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
        this.msg = "操作失败";
    }

    public void invokeFail(String msg) {
        this.data = null;
        this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
        if (msg != null && !msg.equals("")) {
            this.msg = msg;
        }
    }

    public void invokeSuccess() {
        this.code = HttpStatus.OK.value();
        this.msg = "操作成功";
    }

    public void invokeSuccess(String msg) {
        if (msg != null && !msg.equals("")) {
            this.msg = msg;
        }
        this.code = HttpStatus.OK.value();
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Map<?, ?> getMap() {
        return map;
    }

    public void setMap(Map<?, ?> map) {
        this.map = map;
    }

    public List<Map<String, Object>> getList() {
        return list;
    }

    public void setList(List<Map<String, Object>> list) {
        this.list = list;
    }
}
